package com.solidumgame.ninja.knife
{
	import Box2D.Collision.Shapes.b2Shape;
	
	import com.pblabs.box2D.Box2DManagerComponent;
	import com.pblabs.box2D.Box2DSpatialComponent;
	import com.pblabs.box2D.PolygonCollisionShape;
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.core.ObjectType;
	import com.solidumgame.ninja.ingredient.whole.WholeIngredient;
	
	import flash.geom.Point;
	
	public class KnifeSpatialComponent extends Box2DSpatialComponent
	{
		public function KnifeSpatialComponent()
		{
			super();
			
			this.spatialManager = PBE.lookupEntity("SpatialManager").lookupComponentByName("Manager") as Box2DManagerComponent;
			this.position = new Point(-220, 0);
			this.size = new Point(97, 52);
			this.rotation = -5;
			this.canMove = true;
			this.canRotate = true;
			this.canSleep = true;
			this.collisionType = new ObjectType(Knife.TYPE);
			this.collidesWithTypes = new ObjectType(WholeIngredient.TYPE);
			createKnife();
		}
				
		private function createKnife():void{
			
			var ratioX:Number = 53;
			var ratioY:Number = 12;
			
			this.size = new Point(ratioX*2, ratioY*2);
			
			//Handgrip
			
			var knifeHandGrip:PolygonCollisionShape = new PolygonCollisionShape();
			knifeHandGrip.density = 0;
			knifeHandGrip.friction = 1;
			knifeHandGrip.vertices = [new Point(-5/ratioX, -26/ratioY),new Point(48.5/ratioX, -26/ratioY),new Point(48.5/ratioX, 26/ratioY),new Point(17.5/ratioX, 26/ratioY)];

			//Edge
	
			var knifeEdge:PolygonCollisionShape = new PolygonCollisionShape();
			knifeEdge.density = 0;
			knifeEdge.friction = 1;
			knifeEdge.vertices = [new Point(-5/ratioX, -12/ratioY),new Point(53/ratioX, -12/ratioY),new Point(53/ratioX, 12/ratioY),new Point(-5/ratioX, 12/ratioY)];
			
			this.collisionShapes = new Array();
			//this.collisionShapes.push(hammerBody);
			this.collisionShapes.push(knifeEdge);
		}
		
		override protected function onReset():void{
			
			super.onReset();
			var shape:b2Shape = this.body.m_shapeList;
			
			while(shape!=null){
				shape.m_isSensor = true;
				shape = shape.m_next;
			}
			
		}
	
	}
}